package com.a214.yxz.yuejian013.Activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.a214.yxz.yuejian013.Base.BaseSActivity;
import com.a214.yxz.yuejian013.Listener.ServiceListener;
import com.a214.yxz.yuejian013.Model.ResModel;
import com.a214.yxz.yuejian013.R;

public class UserSettingChangeInfoActivity extends BaseSActivity {

    private ImageButton return_btn;
    private TextView save;
    private LinearLayout photo_L;
    private ImageView photo;
    private EditText nickName;
    private ResModel model = new ResModel("",getSessionID());
    private ServiceListener<String> listener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_setting_change_info);

        return_btn= (ImageButton) findViewById(R.id.user_setting_changeInfo_return_btn);
        save= (TextView) findViewById(R.id.user_setting_changeInfo_save);
        photo_L= (LinearLayout) findViewById(R.id.user_setting_changeInfo_photo);
        photo= (ImageView) findViewById(R.id.user_setting_changeInfo_photo_img);
        nickName= (EditText) findViewById(R.id.user_setting_changeInfo_nickName_editText);

        listener=new ServiceListener<String>() {
            @Override
            public void onResponse(String l) {
                Toast.makeText(UserSettingChangeInfoActivity.this, "保存成功", Toast.LENGTH_SHORT).show();
                finish();
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(UserSettingChangeInfoActivity.this, msg, Toast.LENGTH_SHORT).show();
            }
        };

        return_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SharedPreferences sharedPreferences = getSharedPreferences("user_info", Context.MODE_PRIVATE);
                model.updateUserName(sharedPreferences.getString("user_id","408"),nickName.getText().toString(),listener);
            }
        });
    }
}
